import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { formatDate } from './demo.entity';

@Entity()
export class DemoCategory {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({
    length: 50,
    collation: 'utf8mb4_bin',
    type: 'varchar',
    comment: '名称',
  })
  name: string;

  @CreateDateColumn({
    transformer: {
      to: (value) => value,
      from: (value) => {
        return formatDate(value);
      },
    },
    nullable: false,
    comment: '创建时间',
    length: 0,
    update: false,
  })
  createAt: string;

  @UpdateDateColumn({
    transformer: {
      to: (value) => value,
      from: (value) => {
        return formatDate(value);
      },
    },
    nullable: false,
    comment: '最后修改时间',
  })
  updateAt: string;

  @DeleteDateColumn({
    transformer: {
      to: (value) => value,
      from: (value: Date) => {
        return formatDate(value);
      },
    },
    nullable: true,
    comment: '删除时间',
  })
  deleteAt: string | null;
}
